package neu.competition.controller.edge;

import neu.competition.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping()
public class RegisterController {
    @Autowired
    UserService us;

    @GetMapping("/edge/register")
    public String register_index(Model model) {
        return "user/register";
    }

    @RequestMapping("/edge/reg_user")
    public String register(String userid, String email, MultipartFile image, String name, String password, String occupation, Model model) {
        System.out.println(image);

        boolean res = us.register(userid, email, name, image, occupation, password);
        if (res)
            model.addAttribute("msg", "注册成功");
        else
            model.addAttribute("msg", "注册失败");
        return "redirect:/edge/login";
    }
}
